package world;

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;

import world.ai.AI;
import world.endCondition.EndCondition;
import world.unit.Unit;
import display.camera.Camera;

public final class World
{
	private ArrayList<EndCondition> endConditions = new ArrayList<EndCondition>();
	private ArrayList<WorldListener> listeners = new ArrayList<WorldListener>();
	private ArrayList<Unit> units = new ArrayList<Unit>();
	private AI[] ais;
	
	/**
	 * stores total elapsed game time
	 */
	long gameTime = 0;
	
	public World(AI[] ais)
	{
		this.ais = ais;
	}
	public void drawWorld(Graphics2D g, Camera c)
	{
		g.setColor(new Color(0, 142, 0)); //a nice dark green
		g.fillRect(0, 0, c.getPhysicalViewDim()[0], c.getPhysicalViewDim()[1]);
		for(Unit u: units)
		{
			u.drawUnit(g);
		}
	}
	public void update(double tdiff)
	{
		for(Unit u: units)
		{
			u.updateUnit(tdiff, this);
		}
		for(EndCondition condition: endConditions)
		{
			if(condition.gameEnd(this))
			{
				for(WorldListener listener: listeners)
				{
					listener.endConditionReached(condition, condition.getEndMessage());
				}
			}
		}
	}
}
